import ffmpeg
import pytube


def video_add_audio(video_file, audio_file, file_name):
    """
     视频添加音频
    :param file_name: 传入视频文件的路径
    :param mp3_file: 传入音频文件的路径
    :return:
    """
    audio = ffmpeg.input(audio_file)
    video = ffmpeg.input(video_file)
    ffmpeg.output(audio, video, file_name).run()
    # ffmpeg.concat(video, audio, v=1, a=1).output(file_name).run(overwrite_output=True)


link = "https://www.youtube.com/watch?v=bON-KPiiNCk"
yt = pytube.YouTube(link)
name = yt.title
print("Title:", name)

# print("Author:", yt.author)
# print("Published date:", yt.publish_date.strftime("%Y-%m-%d"))
# print("Number of views:", yt.views)
# print("Length of video:", yt.length, "seconds")
# yt.streams.get_highest_resolution().download()


# download audio only
mp4 = name + "_former.mp4"
# yt.streams.filter(res="2160p", progressive=False).first().download(filename=mp4)
mp3 = name + "_former.mp3"
# yt.streams.filter(abr="160kbps", progressive=False).first().download(filename=mp3)
video_add_audio(mp4, mp3, name)
print("Video successfullly downloaded from", link)
# pideo = ffmpeg.input("video.mp4")
